#include <nice2d/widgets/dock.h>
#include <nice2d/widgets/control.h>

class DockData
{
public:
    bool dock = false;
    HMode hMode;
    VMode vMode;
    float xoffset = 0.0f;
    float yoffset = 0.0f;
    bool dirty = true;
};

Dock::Dock():
    data(new DockData())
{  
}

Dock::~Dock()
{
}

void Dock::setDock(bool dock)
{
    data->dock = dock;
}

bool Dock::isDock() const
{
    return data->dock;
}

void Dock::setHorizontalMode(HMode mode)
{
    data->hMode = mode;
    data->dirty = true;
}

HMode Dock::getHorizontalMode() const
{
    return data->hMode;
}

void Dock::setVertical(VMode mode)
{
    data->vMode = mode;
    data->dirty = true;
}

VMode Dock::getVertical() const
{
    return data->vMode;
}

void Dock::setXOffset(float offset)
{
    data->xoffset = offset;
    data->dirty = true;
}

float Dock::getXOffset() const
{
    return data->xoffset;
}

void Dock::setYOffset(float spacing)
{
    data->yoffset = spacing;
    data->dirty = true;
}

float Dock::getYOffset() const
{
    return data->yoffset;
}

void Dock::adjustControl(ControlPointer control, const sf::Vector2f &parentSize)
{
    if(!control || !isDock() || !data->dirty)
        return;

    data->dirty = false;
    auto controlBox = control->getBoundingBox();
    auto position = Control::adjustPosition({0.0f,0.0f,parentSize.x,parentSize.y},{controlBox.width,controlBox.height},data->hMode,data->vMode,data->xoffset,data->yoffset);
    control->setPosition(position);
}
